package com.mybatis.dao;
import com.mybatis.domain.User;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;
import java.util.Map;

public interface IUserDao {


    /**
     * 根据用户id查询用户及用户下的订单信息
     * @param id
     * @return
     */
    @Select("select * from t_user where id = #{id}")
    @Results({
            //如果要映射id属性，下面这行不能省略
            @Result(property = "id", column = "id"),
            @Result(property = "orderList", column = "id", many = @Many(select = "com.mybatis.dao.IOrderDao.findOrderByUserId", fetchType = FetchType.LAZY))
    })
    User findUserById(int id);

    @Insert("insert into t_user(username, birthday) values(#{username}, #{birthday})")
    @SelectKey(statement = {"select last_insert_id()"}, keyProperty = "id", keyColumn = "key", before = false, resultType = Integer.class)
    void insertUser(User user);
}
